/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.bridge;

import ru.jSkyRoom.bridge.major.MajorBridge;
import java.util.Collection;
import java.util.List;
import ru.jSkyRoom.factory.BridgeFactory;
import ru.jSkyRoom.interfaces.Armor;
import ru.jSkyRoom.interfaces.Enchantment;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.interfaces.Keyword;
import ru.jSkyRoom.interfaces.Major;
import skyproc.ARMO;
import skyproc.ENCH;
import skyproc.FormID;
import skyproc.GRUP_TYPE;
import skyproc.KYWD;
import skyproc.MajorRecord;
import skyproc.Mod;

/**
 *
 * @author Rakev
 */
public class ModBridge extends JSkyBridge<Mod> implements JSkyMod {

    public ModBridge(Mod adapting) {
        super(adapting);
    }

    @Override
    public <E extends Major> E makeCopy(E copingMajor, String newEDID) {
        if (copingMajor instanceof MajorBridge) {
            MajorBridge bridge = (MajorBridge) copingMajor;
            MajorRecord templateRecord = bridge.getAdapting();
            MajorRecord copyRecord = getAdapting().makeCopy(templateRecord, newEDID);
            return (E) getBridgeFactory().createBridge(copyRecord, bridge.getClass());
        }
        throw new IllegalArgumentException("Support only MajorBridge");
    }

    @Override
    public void addAsOverrides(JSkyMod mod, GRUP_TYPE... grupTypes) {
        if (mod instanceof ModBridge) {
            Mod addingMod = ((ModBridge) mod).getAdapting();
            getAdapting().addAsOverrides(addingMod, grupTypes);
            return;
        }
        throw new IllegalArgumentException("Support only MajorBridge");

    }

    @Override
    public Major getMajor(FormID id, GRUP_TYPE... lookingGrups) {
        MajorRecord findedRecord = getAdapting().getMajor(id, lookingGrups);
        if (findedRecord != null) {
            return (Major) getBridgeFactory().createBridge(findedRecord);
        }
        return null;
    }

    @Override
    public Major getMajor(String editId, GRUP_TYPE... lookingGrups) {
        MajorRecord findedRecord = getAdapting().getMajor(editId, lookingGrups);
        if (findedRecord != null) {
            return (Major) getBridgeFactory().createBridge(findedRecord);
        }
        return null;
    }

    @Override
    public boolean contains(FormID form) {
        return getAdapting().contains(form);
    }

    @Override
    public boolean contains(Major major) {
        return contains(major.getForm());
    }

    @Override
    public List<Armor> getArmors() {
        List<ARMO> armos = getAdapting().getArmors().getRecords();
        return (List) getBridgeFactory().createBridges(armos);
    }

    @Override
    public List<Enchantment> getEnchantments() {
        List<ENCH> enchs = getAdapting().getEnchantments().getRecords();
        return (List) getBridgeFactory().createBridges(enchs);
    }

    @Override
    public List<Keyword> getKeywords() {
        List<KYWD> keys = getAdapting().getKeywords().getRecords();
        return (List) getBridgeFactory().createBridges(keys);
    }
}
